import tkinter as tk

from api.high_api import Event
from api.mod.eventGenerato import EventGenerator
from api.mod.modLoader import ModLoader
from framework.syntacticSugar.EventEntiys import EventEntiys

mode = [0, 0]


def put(ele):
    mode[1] = 0

    ele.delete(1.0, tk.END)
    ele.insert(tk.END, str(ModLoader().eventall))


def only_events(ele):
    mode[0] = 0
    ele.delete(1.0, tk.END)
    ele.insert(tk.END, str(ModLoader().event_name))


def aput(ele):
    mode[1] = 1
    ele.delete(1.0, tk.END)
    for k, i in ModLoader().authority.items():
        ele.insert(tk.END, f"{k} -> {i}\n")


def aonly_auth(ele):
    mode[0] = 1
    ele.delete(1.0, tk.END)
    for i in list(ModLoader().authority.keys()):
        ele.insert(tk.END, i + '\n')


def run_me():
    a = EventGenerator("囚禁", EventEntiys())
    print(a.render_json().get("囚禁"))


def run_event(ele, ele2):
    default = EventEntiys()
    json = Event.NoRoundEventExec(event_name=ele.get(), event_entiys=default)
    ele2.delete(1.0, tk.END)
    ele2.insert(tk.END, str(json.get(ele.get())))


def effect(ele):
    ele.delete(1.0, tk.END)
    ele.insert(tk.END, str(ModLoader().event_effect_name))

def show():
    win = tk.Tk()
    win.title("魔幻的古大陆传奇控制台")
    win.geometry("1920x1080")

    tk.Label(text="游戏中加载的事件").place(x=93, y=48, )
    tk.Button(text="刷新", command=lambda: put(my_event)).place(x=343, y=36)
    tk.Button(text="只显示事件", command=lambda: only_events(my_event)).place(x=233, y=36, )
    my_event = tk.Text()
    my_event.place(x=93, y=68, width=300, height=300)

    entry = tk.Entry()
    entry.place(x=1000, y=35)
    event_response = tk.Text()
    event_response.place(x=900, y=68, width=300, height=300)
    tk.Button(text='测试请求', command=lambda: run_event(entry, event_response)).place(x=900, y=35, width=90)

    tk.Label(text="游戏中加载的权能").place(x=493, y=48, )
    tk.Button(text="刷新", command=lambda: aput(my_auth)).place(x=743, y=36)
    tk.Button(text="只显示事件", command=lambda: aonly_auth(my_auth)).place(x=633, y=36, )
    my_auth = tk.Text()
    my_auth.place(x=493, y=68, width=300, height=300)

    my_EffectScript = tk.Text()
    my_EffectScript.place(x=93, y=468, width=300, height=300)
    tk.Label(text="游戏中加载EffectScript").place(x=93, y=448, )
    tk.Button(text="刷新", command=lambda: effect(my_EffectScript)).place(x=343, y=436)
    tk.Button(text="只显示事件", command=lambda: effect(my_EffectScript)).place(x=233, y=436, )



    def reload_all():
        put(my_event)
        aput(my_auth)

    tk.Button(text="刷新全部", command=reload_all).place(x=0, y=0)
    win.mainloop()
